<?php
/**
 *Copyright (c) 2012 copyright @ Xuehui YANG
 *website: http://www.bagualu.net
 *
 * @author Xuehui YANG southpasszju@gmail.com
 * @version 0.1 
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
*/
$ROOT="." ; 
$bookname_dic_file=$ROOT . "/dic/bookname.dic" ;

$bookname_dic=file_get_contents($bookname_dic_file);
$booknames=explode("\n",$bookname_dic);
$bookname="";
$found=0;
foreach ($booknames as $book){
	foreach ($title_candidates as $candi){
		echo "check " . $book . " against " . $candi . "\n" ;
		if( mb_strstr($candi,$book) ){
			$bookname=$book;
			$found=1;
			break;		
		}
	}
	if($found ==1 ){ break; } 
}

$chp_pattern=array('(第[^\/]+章)[\/　]+([　\x{4e00}-\x{9fff}]+)',
'(第[^\/]+回)[\/　]+([　\x{4e00}-\x{9fff}]+)',
'(第[^\/]+卷)[\/　]+([　\x{4e00}-\x{9fff}]+)',
'(卷[^　]+)[\/　]+([　\x{4e00}-\x{9fff}]+)');
$chp_pattern2=array(
'([　\x{4e00}-\x{9fff}]+)(第[^　\/]+)');
$found=0;
$tstr=implode("/",$title_candidates);
echo "check for chapter title " . $tstr . "\n" ;
foreach( $chp_pattern as $pa) {
	if(preg_match("/$pa/u",$tstr,$matches)){
		$chapter_index=$matches[1];
		$chapter_title=$matches[2];
		if(count_hz_num($chapter_title) > 1){
			break ;
			$found=1;
		}else{
		}
	}
}
if($found == 0){
	foreach( $chp_pattern2 as $pa) {
		if(preg_match("/$pa/u",$tstr,$matches)){
			$chapter_index=$matches[2];
			$chapter_title=$matches[1];
			if(count_hz_num($chapter_title) > 1){
				break ;
				$found=1;
			}else{
			}
		}
	}
}

echo "bookname:"  . $bookname . "\n" ;
echo "chapter index :"  . $chapter_index . " chapter_title: " . $chapter_title . "\n" ;
print_r($chapter_paragraphes);

echo "found :" . $found. "\n" ;
if(count_hz_num($chapter_title) > 0){
	echo "gen xml\n";
	require("genxml.php");
}

?>
